from django.shortcuts import render
from django.core.urlresolvers import reverse
from django.http import HttpResponse,JsonResponse
from web.settings import BASE_DIR
import time,random

# Create your views here.

# 首页显示
def index(request):
    return render(request,'admin/index.html')


# 文件上传
def uploads(myfile):
    #
    #  使用时间与随机模块 拼接头像文件名
    filename = str(time.time())+ str(random.randint(10000,99999))+ '.'+ myfile.name.split('.').pop()
    print(filename)
    # 打开一个文件
    destination = open(BASE_DIR+"/static/pics/"+filename,'wb+')
   # 写入文件
    print(myfile.chunks())
    for chunk in myfile.chunks():
        destination.write(chunk)
    destination.close()
    return "/static/pics/"+filename







